package org.wlgzs.shop.test;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

class Solution {
    public boolean canJump(int[] nums) {
        if(nums[0]==0&&nums.length!=1){
            return false;
        }
        A:for(int d=1;d<nums.length-1;d++){
            if(nums[d]==0){
                if(select(nums,d,1)){
                    continue A;
                }
                else {
                    return false;
                }
            }
        }
        return true;
    }

    boolean select(int[] num,int d,int b){
        if(num[d]>=b){
            return true;
        }
        else if (d==0){
            return false;
        }
        return select(num,d-1,b+1);
    }
}




//快乐数

public class test{
    public static void main(String[] args) {
        System.out.println(isHappy(19));
    }

    static boolean isHappy(int n) {
        HashSet hashSet=new HashSet();
        int size=0;
        while(true) {
            char[] a = (n + "").toCharArray();
            int number = 0;
            for (int d = 0; d < a.length; d++) {
                number += (a[d] - 48) * (a[d] - 48);
            }
            hashSet.add(number);
            if (number == 1) {
                return true;
            }
            if(hashSet.size()==size){
                return false;
            }
            size++;
            n=number;
        }
    }

}

